package com.project2.myjunit;


import com.project2.myjunit.annotions.*;
import com.project2.testJunit4.Calculation;
import org.apache.log4j.Logger;
import org.testng.Assert;

public class TestCalculator {

    private static Logger log= Logger.getLogger(   TestCalculator.class.getName() );
    static Calculation js;  //待测试的功能单元

    //@Test执行前一定运行构造函数
    public TestCalculator(){
        log.info( "CalculationTest的构造方法[生命周期]");
    }


    @MyBeforeClass  //在单元测试开始前执行,
    public static void beforeClass(){
        log.info("beforeClass()");
        js=new Calculation();
    }

    @MyBeforeClass
    public static void beforeClass2(){
        log.info("beforeClass2()");
        js=new Calculation();
    }

    @MyBefore
    public void before(){
        log.info( "before()");
    }

    @MyBefore
    public void before2(){
        log.info( "before2()");
    }

    @MyTest
    public void testAdd(){
        log.info(  "testAdd() ");
        Assert.assertEquals(7, js.add(3,4)  );
    }

    @MyTest
    public void testSub(){
        log.info("testSub()");
        Assert.assertEquals(-1, js.sub(3,4)  );
    }

    @MyIgnore
    public void testIgnore(){
        log.info("ignore()");
    }

    @MyAfter
    public void after(){
        log.info("after");
    }

    @MyAfterClass
    public static void afterClass(){
        log.info("afterclass");
    }
}
